package com.boruan.qq.zxgylibrary.service.presenter;

import android.content.Context;

import com.boruan.qq.zxgylibrary.base.BasePresenter;
import com.boruan.qq.zxgylibrary.base.BaseView;
import com.boruan.qq.zxgylibrary.service.manager.DataManager;
import com.boruan.qq.zxgylibrary.service.manager.GXDrugModule;
import com.boruan.qq.zxgylibrary.service.model.OrderDetailBean;
import com.boruan.qq.zxgylibrary.service.model.PayResultBean;
import com.boruan.qq.zxgylibrary.service.view.PayView;
import com.convenient.qd.core.bean.BaseResBean;
import com.convenient.qd.core.net.BaseHttpObserver;

/**
 * Created by 崔琦 on 2019/9/20.
 * des: ....
 */

public class PayPresenter implements BasePresenter{

    private Context mContext;
    private PayView payView;
    private DataManager dataManager;

    public PayPresenter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void onCreate() {
        dataManager = new DataManager(mContext);
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onStop() {
        payView = null;
    }

    @Override
    public void pause() {

    }

    @Override
    public void attachView(BaseView view) {
        payView = (PayView)view;
    }

    private PayResultBean.ResultBean payResultBean;
    public void getPayResultInfo(String tradeId){

        GXDrugModule.getInstance().getPayResultInfo(tradeId, new BaseHttpObserver<BaseResBean<PayResultBean.ResultBean>>() {
            @Override
            public void onSuccess(BaseResBean<PayResultBean.ResultBean> bean) {
                payResultBean = bean.getResult();
                if (payResultBean != null){
                    payView.getPayResultSuccess(payResultBean);
                }
            }

            @Override
            public void onFailure(int i, String msg) {
                payView.getPayResultFailed(msg);
            }
        });

    }

    /**
     * 获取订单详情
     * */
    public void getOrderDetailInfo(String orderId){

        GXDrugModule.getInstance().getOrderDetailInfo(orderId, new BaseHttpObserver<BaseResBean<OrderDetailBean.ResultBean>>() {
            @Override
            public void onSuccess(BaseResBean<OrderDetailBean.ResultBean> bean) {
                if (bean != null){
                    payView.getOrderDetailSuccess(bean.getResult().getState());
                }
            }

            @Override
            public void onFailure(int status, String msg) {
                payView.getOrderDetailFailed(msg);
            }
        });

    }
}
